<template>
  <el-dialog title="奖金池管理" :close-on-click-modal="false" width="70vw" :visible.sync="visible"
             @close="clearDataList()">
    <el-table v-loading="loading" :data="dataForm" border style="width: 100%;" height="500">
      <el-table-column type="index" align="center" width="60px" label="序号"></el-table-column>
      <el-table-column prop="deptName" align="center" label="部门名称" width="600px"></el-table-column>
      <el-table-column prop="total" align="center" label="奖金池总额(元)">
        <template slot-scope="scope">
          {{ $formatNum(scope.row.total) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <el-button type="primary" plain @click="bonusPoolControl(scope.row)">奖金池控制</el-button>
          <el-button type="primary" plain @click="bonusPoolDetail(scope.row)">奖金池使用明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="avue-crud__pagination">
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
                     :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" background
                     layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="clearDataList">关闭</el-button>
    </span>

    <!-- 奖金池控制 -->
    <jjc-gl-kz v-if="jjcGlKzVisible" ref="jjcGlKzRef"></jjc-gl-kz>
    <!-- 奖金池使用明细 -->
    <jjc-gl-mx v-if="jjcGlMxVisible" ref="jjcGlMxRef"></jjc-gl-mx>

  </el-dialog>
</template>
<script>
import {getManagePage} from '@/api/jiangjin/jiangjinjjcxxb'
import JjcGlKz from './jiangjinfpjjfpdjb-jjcgl-kz'
import JjcGlMx from './jiangjinfpjjfpdjb-jjcgl-mx'

export default {
  data() {
    return {
      serchForm: {
        deptIds: ''
      },
      visible: false,
      dataForm: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      loading: false,
      jjcGlKzVisible: false,
      jjcGlMxVisible: false,
    }
  },
  components: {
    JjcGlKz,
    JjcGlMx
  },

  methods: {
    init(deptIds) {
      this.visible = true
      this.serchForm.deptIds = deptIds // 负责部门id集合：格式：xx,xx
      this.getDataForm()
    },

    // 查询下属机构奖金池汇总列表
    getDataForm() {
      this.loading = true
      getManagePage({
        current: this.pageIndex,
        size: this.pageSize
      }).then(response => {
        this.dataForm = response.data.data.records
        this.totalPage = response.data.data.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    clearDataList() {
      this.visible = false
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataForm()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataForm()
    },

    // 显示奖金池控制dialog
    bonusPoolControl(row) {
      this.jjcGlKzVisible = true
      this.$nextTick(() => {
        this.$refs.jjcGlKzRef.init(row.deptId,row.deptName)
      })
    },

    // 显示奖金池使用明细dialog
    bonusPoolDetail(row) {
      this.jjcGlMxVisible = true
      this.$nextTick(() => {
        this.$refs.jjcGlMxRef.init(row.deptId,row.deptName)
      })
    }

  }
}

</script>

<style scoped>

</style>
